package com.shengqi.xinnongren.work.ui.user.presenter;

import com.google.gson.Gson;
import com.shengqi.xinnongren.common.base.BasePresenter;
import com.shengqi.xinnongren.common.config.network.Constants;
import com.shengqi.xinnongren.common.config.network.RetrofitHelper;
import com.shengqi.xinnongren.common.config.user.UserManager;
import com.shengqi.xinnongren.common.md5.SafeUtils;
import com.shengqi.xinnongren.common.utils.LogUtil;
import com.shengqi.xinnongren.work.model.HttpRespond;
import com.shengqi.xinnongren.work.ui.Global;
import com.shengqi.xinnongren.work.ui.user.model.OrderDetailsBean;
import com.shengqi.xinnongren.work.ui.user.model.OrderDetailsBean2;
import com.shengqi.xinnongren.work.ui.user.view.OrderDetails2View;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class OrderDetails2Presenter extends BasePresenter<OrderDetails2View> {
    public void getOrderDetails(String orderId) {
        getView().showLoadingView();
        Map<String, Object> map = new HashMap<>();
        map.put("orderId", orderId);
        JSONObject aesJsonData = Constants.getAESJsonData(map, UserManager.getInstance().getToken());
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), aesJsonData.toString());
        addTask(RetrofitHelper.getInstance().getService().getOrderDetails2(requestBody), s->{
            getView().hideLoadingView();
            HttpRespond<String> httpResult = Global.getHttpResult(s);
            if (httpResult.result==1) {
                LogUtil.e("订单详情数据：" +httpResult.data);
                OrderDetailsBean2 bean = new Gson().fromJson(httpResult.data, OrderDetailsBean2.class);
                getView().onGetOrderDetails(bean);
            } else
                getView().onRequestFailed(httpResult.message);
        });
    }


//
//    /**
//     * 确认收货取货
//     *
//     * @param id
//     */
//    public void confirmOrder(String id) {
//        Map<String, Object> map = new HashMap<>();
//        map.put("orderId", id);
//        JSONObject aesJsonData = Constants.getAESJsonData(map, UserManager.getInstance().getToken());
//        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), aesJsonData.toString());
//        addTask(RetrofitHelper.getInstance().getService().confirmOrder(requestBody), respond -> {
//            getView().hideLoadingView();
////            if (respond.result == 1) {
////                getView().showConfirmOrderRes(respond.message);
////            } else
////                getView().showRequestFailed(respond.message);
//        });
//    }
}
